<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>实验室助理工作管理系统</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
    <meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
    <meta name="author" content="yinqi">
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/css/materialdesignicons.min.css}">
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/css/style.min.css}">
    <!--对话框-->
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/js/jconfirm/jquery-confirm.min.css}">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
</head>
<body>

<!--页面主要内容-->
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header"><h4>招聘计划信息列表</h4></div>
            <div class="card-header">
                <div class="form-group">
                    <div class="row">
                        <div class="col-xs-7">
                            <form class="form-inline" action="" >
                                <div class="form-group">
                                    <label class="sr-only" for="example-if-email">搜索</label>
                                    <input class="form-control" type="text" id="example-if-email" name="name" placeholder="search..">
                                </div>
                                <div class="form-group">
                                    <button class="btn btn-default" type="submit">搜索</button>
                                </div>
                            </form>
                        </div>
                        <div class="col-xs-3">
                            <button class="btn btn-primary m-r-5" id="add"><i class="mdi mdi-plus"></i>填写招聘计划</button>
                        </div>
                        <div class="col-xs-2">
                            <a class="btn btn-yellow m-r-5" href="/toRecruitmentPlan"><i class="mdi mdi-refresh"></i>刷新</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="card-body">
                <table class="table table-bordered table-hover">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>招聘计划编号</th>
                        <th>招聘计划名称</th>
                        <th>岗位</th>
                        <th>岗位要求</th>
                        <th>招聘人数</th>
                        <th>申请部门</th>
                        <th>申请人</th>
                        <th>开始时间</th>
                        <th>截至时间</th>
                        <th>审核状态</th>
                        <th>审核意见</th>
                        <th>审核是否通过</th>
                    </tr>
                    </thead>
                    <tbody id="tb_teacher">
                    </tbody>
                </table>
            </div>

            <!-- 模态框 -->
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title" id="myModalLabel">添加招聘计划</h4>
                        </div>
                        <div class="modal-body">

                            <!--页面主要内容-->
                            <div class="row">
                                <div class="col-lg-12">
                                    <div class="card">
                                        <div class="card-body">
                                            <form action=""  class="row" id="userForm" name="myform">
                                                <div class="form-group col-md-12">
                                                    <label for="planId">招聘计划编号</label>
                                                    <input type="text" class="form-control" id="planId" name="" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label for="planName">招聘计划名称</label>
                                                    <input type="text" class="form-control" id="planName" name="" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label for="wordName">岗位名称</label>
                                                    <input type="text" class="form-control" id="wordName" name="" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label for="jobRequirements">岗位要求</label>
                                                    <input type="text" class="form-control" id="jobRequirements" name="" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label for="recruitsNumber">招聘人数</label>
                                                    <input type="text" class="form-control" id="recruitsNumber" name="" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label for="deptName">所属部门</label>
                                                    <div class="form-controls">
                                                        <select name="" class="form-control" id="deptName" required>
                                                            <option value="">选择部门</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label for="applicant">申请人</label>
                                                    <input type="text" class="form-control" id="applicant" name="" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label>开始时间</label>
                                                    <input type="text" class="layui-input" id="startTime" name="startTime" placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" required>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label>截止时间</label>
                                                    <input type="text" class="layui-input" id="endTime" name="endTime" placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" required>
                                                </div>
                                            </form>

                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!--End 页面主要内容-->
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" onclick="modify()">提交</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--End 页面主要内容-->

<script type="text/javascript" th:src="@{/js/jquery-3.6.0.min.js}"></script>
<!--<script type="text/javascript" th:src="@{/Light-Year-Admin/js/jquery.min.js}"></script>-->
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/bootstrap.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/perfect-scrollbar.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/main.min.js}"></script>
<!--消息提示-->
<script th:src="@{/Light-Year-Admin/js/bootstrap-notify.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/lightyear.js}"></script>
<!--对话框-->
<script th:src="@{/Light-Year-Admin/js/jconfirm/jquery-confirm.min.js}"></script>
<!-- layui -->
<script type="text/javascript" th:src="@{/layui/layui.js}"></script>

<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //日期时间选择器
        laydate.render({
            elem: '#startTime'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#endTime'
            ,type: 'datetime'
        });
    });
</script>

<script type="text/javascript">

    $(function () {
        // 查询所有数据
        getRecruitmentPlan();
    });

    // 打开新增页面
    $("#add").click(function () {
        // 清空模态框表单
        reset();
        // 查询所有部门，向下拉框中赋值
        $.ajax({
            url: "/department/findAll2",
            type: "GET",
            success: function (result) {
                console.log(result)
                if (result != null){
                    $('#deptName').empty();//加载列表前先清掉子项，防止重复累计叠加
                    for(var i=0;1<result.length;i++){
                        var name = result[i].deptName;
                        var sel = document.getElementById("deptName");//获取下拉选对象
                        var option = new Option(name,name); // Option()构造函数接受两个参数：文本(text)和值(value);第二个参数可选
                        sel.options.add(option);
                    }
                }

            }
        });
        // 打开模态框
        $('#myModal').modal('show');
    });

    // 查询所有数据
    function getRecruitmentPlan() {
        $.ajax({
                type: "GET",
                url: "/recruitmentPlan/findAll",
                contentType: 'application/json;charset=utf-8', //设置请求头信息
                dataType: "json",
                success: function (result) {
                    let html = "";
                    let statusStr = '';
                    let isOpinionStr = '';
                    let auditOpinion = '';
                    //遍历结果集result,
                    for(let i = 0,j=1;i<result.length;i++,j++){
                        // 判断审核状态
                        if (result[i].status == 1){
                            statusStr = '已审核';
                            auditOpinion = result[i].auditOpinion;
                        }else {
                            statusStr = '未审核';
                            auditOpinion = '';
                        }
                        // 判断审核是否通过
                        if (result[i].isOpinion == 1){
                            isOpinionStr = '已通过';
                        }else if (result[i].isOpinion == 0){
                            isOpinionStr = '未通过';
                        }else {
                            isOpinionStr = '';
                        }

                        html += "<tr>"+
                            "<td>"+j+"</td>"+
                            "<td>"+result[i].planId+"</td>"+
                            '<td>'+result[i].planName+"</td>"+
                            '<td>'+result[i].wordName+"</td>"+
                            "<td>"+result[i].jobRequirements+"</td>"+
                            "<td>"+result[i].recruitsNumber+"</td>"+
                            "<td>"+result[i].deptName+"</td>"+
                            "<td>"+result[i].applicant+"</td>"+
                            "<td>"+result[i].startTime+"</td>"+
                            "<td>"+result[i].endTime+"</td>"+
                            "<td>"+statusStr+"</td>"+
                            "<td>"+auditOpinion+"</td>"+
                            "<td>"+isOpinionStr+"</td>"+
                            "</tr>";
                    }
                    //将html标签拼接在html中
                    $("#tb_teacher").html(html);
                }
            }
        )
    }

    // 新增or修改
    function modify() {
        //获取模态框数据
        var planId = $("#planId").val();
        var planName = $("#planName").val();
        var wordName = $("#wordName").val();
        var jobRequirements = $("#jobRequirements").val();
        var deptName = $("#deptName").val();
        var recruitsNumber = $("#recruitsNumber").val();
        var applicant = $("#applicant").val();
        var startTime = $("#startTime").val();
        var endTime = $("#endTime").val();

        var param = {"planId": planId, planName: planName, jobRequirements: jobRequirements, deptName: deptName,recruitsNumber: recruitsNumber, applicant: applicant,startTime: startTime,endTime:endTime,wordName:wordName};

        $.ajax({
            url: "/recruitmentPlan/add",
            type: "POST",
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(param),
            success: function (data) {
                if(data.code == 200 ){
                    reset();
                    $('#myModal').modal('hide');
                    getRecruitmentPlan();
                    lightyear.notify('添加成功', 'success', 500, 'mdi mdi-emoticon-happy', 'top', 'center');
                }else{
                    reset();
                    $('#myModal').modal('hide');
                    lightyear.notify('添加失败,招聘计划编号不能重复', 'danger', 800, 'mdi mdi-emoticon-happy', 'top', 'center');
                }
            }
        });
    }

    // 清空模态框
    function reset() {
        $("#planId").val("");
        $("#planName").val("");
        $("#wordName").val("");
        $("#jobRequirements").val("");
        $("#deptName").val("");
        $("#recruitsNumber").val("");
        $("#applicant").val("");
        $("#startTime").val("");
        $("#endTime").val("");
    }

</script>
</body>
</html>